package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.pudao.PuDaoLianYangScoreBData;
import com.ucredit.babel.common.model.third.pudao.PuDaoLianYangScoreBRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 联洋-黑卡定制分B
 *
 * @author guoqiang
 */
public class PuDaoLianYangScoreBParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 联洋-黑卡定制分B
     *
     * @param model
     * @throws InterruptedException
     * @throws IOException
     */
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        PuDaoLianYangScoreBRecord obj = (PuDaoLianYangScoreBRecord) model;
        PuDaoLianYangScoreBData scoreData = obj.getData();
        PuDaoLianYangScoreBData.LianYangScoreBData data = scoreData.getData();
        StringBuilder sb = getBaseInfo(obj, successful);
        sb.append(formatValue(scoreData.getFlag())).append(CRT001);
        sb.append(formatValue(data.getResultCode())).append(CRT001);
        sb.append(formatValue(data.getTransationId())).append(CRT001);
        sb.append(formatValue(data.getMessage())).append(CRT001);
        PuDaoLianYangScoreBData.LianYangScoreBResultBody lianyangbody = data.getResultBody() == null ? new PuDaoLianYangScoreBData.LianYangScoreBResultBody() : data.getResultBody();
        sb.append(formatValue(lianyangbody.getLrHkxdB())).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_pudaolianyang_score_b_inc";
    }

    @Override
    public String getType() {
        return RecordType.PD_LIANYANG_SCORE_B.toString();
    }

    @Override
    public String getComment() {
        return "联洋-黑卡定制分B";
    }

}
